<template>
  <div class="app-container">
    <a-title @clickPreview="preview" />
    <el-form :model="queryParams" ref="queryForm" :inline="true" label-width="68px">
      <el-form-item label="网站名称" prop="title">
        <el-input
          v-model="queryParams.title"
          placeholder="请输入网站名称"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="部委" prop="general">
        <el-input
          v-model="queryParams.general"
          placeholder="请输入部委"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="地区" prop="city">
        <el-input
          v-model="queryParams.city"
          placeholder="请输入地区"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="行业" prop="industry">
        <el-input
          v-model="queryParams.industry"
          placeholder="请输入行业"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="备注" prop="remark">
        <el-input
          v-model="queryParams.remark"
          placeholder="请输入备注"
          clearable
          size="small"
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-table
      stripe
      v-loading="loading"
      :data="policiesList"
      @sort-change="tableSortChange"
      :default-sort="{prop: 'createTime', order: 'descending'}"
    >
      <el-table-column
        label="网站名称"
        align="center"
        prop="title"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="部委"
        align="center"
        prop="general"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column
        label="地区"
        align="center"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
        prop="city"
      ></el-table-column>
      <el-table-column
        label="行业"
        align="center"
        prop="industry"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
      <el-table-column label="链接" align="center">
        <template slot-scope="scope">
          <el-link type="primary" target="_blank" :href="scope.row.url">{{scope.row.url}}</el-link>
        </template>
      </el-table-column>
      <el-table-column
        label="备注"
        align="center"
        prop="remark"
        :sort-orders="['ascending', 'descending']"
        sortable="custom"
      />
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 预览 -->
    <el-dialog :visible.sync="openPreview" width="80%">
      <iframe :src="manualPreviewUrl" frameborder="0" width="100%" height="700px"></iframe>
    </el-dialog>
  </div>
</template>

<script>
import {
  listPolicies,
  getPolicies,
  delPolicies,
  addPolicies,
  updatePolicies,
  exportPolicies
} from "@/api/businessStandardLibrary/policies/policies";
import aTitle from "@/components/Title";
export default {
  name: "Policies",
  components: { aTitle },
  data () {
    return {
      manualPreviewUrl: null,
      openPreview: false,
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 总条数
      total: 0,
      // 法规导航表格数据
      policiesList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        title: undefined,
        city: undefined,
        general: undefined,
        industry: undefined,
        url: undefined,
        guid: undefined,
        businessCategoryId: undefined,
        sortBy: undefined,
        order: undefined,
        remark:undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        guid: [{ required: true, message: "guid不能为空", trigger: "blur" }]
      }
    };
  },
  created () {
    //    this.queryParams.businessCategoryId = this.$route.params.businessCategoryId;
    this.getList();
  },
  mounted(){
    document.title=document.getElementById("businessNameTitle").innerHTML;
  },
  methods: {
    preview () {
      this.openPreview = true;
      this.manualPreviewUrl = `${this.previewUrl}${encodeURIComponent(
        `${this.operationManual}业务主页/法规导航.xlsx`
      )}&name=${encodeURIComponent("法规导航.xlsx")}`;
    },
    /** 查询法规导航列表 */
    getList () {
      this.loading = true;
      listPolicies(this.queryParams).then(response => {
        this.policiesList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel () {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset () {
      this.form = {
        id: undefined,
        businessCategoryId: undefined,
        title: undefined,
        city: undefined,
        general: undefined,
        remark:undefined,
        industry: undefined,
        url: undefined,
        remark: undefined,
        createBy: undefined,
        createTime: undefined,
        updateBy: undefined,
        updateTime: undefined,
        guid: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery () {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery () {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    tableSortChange (column) {
      this.queryParams.pageNum = 1;

      if (column.order === "descending") {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "desc";
      } else {
        this.queryParams.sortBy = column.prop;
        this.queryParams.order = "asc";
      }
      this.getList();
    }
  }
};
</script>
